package com.stu.day17;

/**
 * @author zy
 * @date 2025/2/17 13:56
 */
public class ThreadCreateDemo extends Thread {
    private int ticket = 10;  // 非静态属性

    @Override
    public void run() {
        for(int i = ticket; i >= 0; i--) {
            //Thread.currentThread()当前线程对象
            System.out.println(Thread.currentThread().getName()+"剩余票数: "+ticket--);

            try {
                Thread.sleep(400);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
class ThreadTest{
    public static void main(String[] args) {
        Thread t1 = new ThreadCreateDemo();
        Thread t2 = new ThreadCreateDemo();

        t1.setName("线程1");
        t2.setName("线程2");
        t1.setPriority(Thread.MIN_PRIORITY);  // 设置优先级为1(1,5,10)

        t1.start();
        t2.start();
    }
}
